{extend name="public/base"}

{block name="title"}就行天下-设置{/block}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/home/css/pay.css" />
{/block}

{block name="main"}
<form>
<div class="pageControl phoneLogin bg-f5">
    <div class="main-top"></div>
    <div class="msui_nav msui_navTop">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">设置支付密码</h1>
        <a href="" class="msui_navTop-right msui_navTop-cnav"><i class="micon-cnav"></i></a>
    </div>
    <div class="login-main bg-fff">
        <p style="text-align: center; margin: .5rem 0;" class="fs065 cl-9999">短信接收号码：{$Think.session.member_username|substr=0,3}******{$Think.session.member_username|substr=-2}</p>
        <div class="verify">
            <input type="hidden" name="mobile" value="{$Think.session.member_username}">
            <div class="login-input phone ">
                <div class="weui-cell__bd">
                    <input type="number" class="weui-input input-content" name="code" placeholder="验证码">
                </div>
                <div class="weui-cell__ft">
                    <a href="" class="cross"></a>
                </div>
            </div>
            <button class="weui_cell-verify js-verify" type="button">
                获取验证码
            </button>
        </div>
        <button class="login-btn cl-f next-btn" type="button" disabled="disabled">下一步</button>
    </div>
</div>
<!--设置支付密码-->
<div id="setPayPassword" class="weui-popup__container">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="modal-content bg-f5">
            <div class="msui_nav msui_navTop">
                <a class="msui_navTop-back close-popup" href="javascript:;"><i class="micon-back"></i></a>
                <h1 class="msui_navTop-title">设置支付密码</h1>
                <a href="" class="msui_navTop-right msui_navTop-cnav"><i class="micon-cnav"></i></a>
            </div>
            <div class="weui-cell noBorder pb10">
                <div class="weui-cell__bd text-center" >
                    <p  class="fs065 line-08">设置6位数支付密码</p>
                </div>
            </div>
            <div class="weui-cell import noBorder">
                <div class="weui-cell__bd">
                    <span></span>
                    <span></span>
                    <span></span>
                    <span></span>
                    <span></span>
                    <span></span>
                    <input class="weui-input" type="number" name="safe_password"  placeholder="">
                </div>
            </div>
            <p class="text-center mtop03 cl-9999 fs06">支付密码用于余额支付、提现等操作，请谨慎保管</p>
            <div class="p05">
                <a href="javascript:;" class="weui-btn cl-f fs065 mtop05 bg-c40 save_safe_password" style="background:#0F8EED;">
                    保 存
                </a>
            </div>
        </div>
    </div>
</div>
</form>
{/block}

{block name="javascript"}
<script>
    $(".input-content").keyup(function () {
        if (!$(this).val() || $(this).val().length != 4) {
            $(".next-btn").attr('disabled', 'disabled');
        } else {
            $(".next-btn").removeAttr('disabled');
        }
    });

    $(".next-btn").click(function () {
        $("#setPayPassword").popup();
    });

    // 输入支付密码
    $(document.body).on('keyup','.import input',function(){
        console.log($(this).val());
        if($(this).val().length>=6){
            var num=$(this).val().substr(0,6);
            $(this).val(num);
            console.log(num)
        }
        $('.import span').each(function(){
            $(this).html('');
        })
        var count=$(this).val();
        var psdLength=$(this).val().length;
        for(var i=0;i<psdLength;i++){
            $('.import span').eq(i).html(count[i]);
        }
    });

    $(".save_safe_password").click(function () {
        var _form = $('form');
        if ($('input[name="safe_password"]').val().length != 6) {
            $.toptip('安全密码必须为6位整数', 'error');
            return false;
        }
        $.ajax({
            type : 'POST',
            url : '?',
            data : _form.serialize(),
            dataType : 'json',
            success : function (msg) {
                if (msg.code == 200) {
                    $.toptip('设置成功', 'success');
                    window.location.href = '{:url("member/index")}';
                } else {
                    $.toptip(msg.msg, 'error');
                }
                console.log(msg);
            }
        });
    });
</script>
{/block}